home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / ShoveIt Deluxe™ by wsanchez / DropScript Source / DropController.m < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.1 KB  |  123 lines

  1. /*
  2.  * DropController.m
  3.  *
  4.  * Wilfredo Sanchez | wsanchez@apple.com
  5.  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  6.  *
  7.  * @APPLE_LICENSE_HEADER_START@
  8.  * 
  9.  * The contents of this file constitute Original Code as defined in and
  10.  * are subject to the Apple Public Source License Version 1.1 (the
  11.  * "License").  You may not use this file except in compliance with the
  12.  * License.  Please obtain a copy of the License at
  13.  * http://www.apple.com/publicsource and read it before using this file.
  14.  * 
  15.  * This Original Code and all software distributed under the License are
  16.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  17.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  18.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  20.  * License for the specific language governing rights and limitations
  21.  * under the License.
  22.  * 
  23.  * @APPLE_LICENSE_HEADER_END@
  24.  */
  25.  
  26. #import <Foundation/Foundation.h>
  27. #import <AppKit/AppKit.h>
  28. #import "DropController.h"
  29.  
  30. @implementation DropController
  31.  
  32. /* Init */
  33.  
  34. - (id) init
  35. {
  36.     if ((self = [super init]))
  37.       {
  38.         /* Set up... */
  39.     myAppIsLaunching             = YES;
  40.     myAppWasLaunchedWithDocument = NO;
  41.     myScriptFileName             = [[[NSBundle mainBundle] pathForResource:@"script" ofType:nil] retain];
  42.  
  43. #if 0
  44.     [[NSNotificationCenter defaultCenter] addObserver:self 
  45.                          selector:@selector(checkATaskStatus:) 
  46.                              name:NSTaskDidTerminateNotification
  47.                            object:nil];
  48. #endif
  49.       }
  50.     return self;
  51. }
  52.  
  53. - (void) dealloc
  54. {
  55.     [myScriptFileName release];
  56.  
  57.     [super dealloc];
  58. }
  59.  
  60. /* Notification handlers */
  61.  
  62. #if 0
  63. - (void) checkATaskStatus: (NSNotification*) aNotification
  64. {
  65.     NSTask* aTask   = [aNotification object];
  66.     int     aStatus = [aTask terminationStatus];
  67.  
  68.     if (aStatus)
  69.     NSLog(@"Task %@ exited with non-zero exit status (%n).", [aTask arguments], aStatus);
  70.     else
  71.     NSLog(@"Task %@ suceeded.", [aTask arguments]);
  72. }
  73. #endif
  74.  
  75. /* Actions */
  76.  
  77. - (void) runScriptWithFiles: (NSArray* ) aFileList
  78. {
  79.     [NSTask launchedTaskWithLaunchPath: myScriptFileName
  80.                  arguments: aFileList];
  81. }
  82.  
  83. /* Application Deletate */
  84.  
  85. - (BOOL) application: (NSApplication*) anApplication
  86.         openFile: (NSString*     ) aFileName
  87. {
  88.     if (myAppIsLaunching) myAppWasLaunchedWithDocument = YES;
  89.  
  90.     [self runScriptWithFiles: [NSArray arrayWithObject: aFileName]];
  91.  
  92.     return YES;
  93. }
  94.  
  95. - (void) applicationWillFinishLaunching: (NSNotification*) aNotification
  96. {
  97.     myAppIsLaunching = YES;
  98. }
  99.  
  100. - (void) applicationDidFinishLaunching: (NSNotification*) aNotification
  101. {
  102.     myAppIsLaunching = NO;
  103.  
  104.     if (myAppWasLaunchedWithDocument)
  105.     [(NSApplication*)[aNotification object] terminate: self];
  106. }
  107.  
  108. /* IB Targets */
  109.  
  110. - (IBAction) open: (id) aSender
  111. {
  112.     NSOpenPanel* anOpenPanel = [NSOpenPanel openPanel];
  113.  
  114.     [anOpenPanel setCanChooseFiles          : YES];
  115.     [anOpenPanel setCanChooseDirectories    : YES];
  116.     [anOpenPanel setAllowsMultipleSelection : YES];
  117.  
  118.     if ([anOpenPanel runModalForTypes:nil] == NSOKButton)
  119.       {
  120.     [self runScriptWithFiles: [anOpenPanel filenames]];
  121.       }
  122. }
  123.  
  124. @end
  125.